package jieduan1_part4;

import java.util.concurrent.locks.ReentrantLock;

public class TicketThreadTest extends Thread {

    private static int tickets = 100;
    private ReentrantLock lock= new ReentrantLock();
    @Override
    public void run() {
        while (true){
            lock.lock();
            if (tickets<0){
                break;
            }else {

                System.out.println(Thread.currentThread()+"------"+"这是第"+tickets-- + "号票");
            }
            lock.unlock();
        }

    }

    public static void main(String[] args) {
        TicketThreadTest ticketThreadTest = new TicketThreadTest();
        TicketThreadTest ticketThreadTest2 = new TicketThreadTest();
        TicketThreadTest ticketThreadTest3 = new TicketThreadTest();
        ticketThreadTest.start();
        ticketThreadTest2.start();
        ticketThreadTest3.start();
    }
}
